<script type="text/javascript">
$(document).ready(function(){
	$("#addUser").on("click",function(){
		window.location.href="${path}/user/addHtml";
	});
	$("button[data-type='editor-button']").on("click",function(e){
		var userId = $(this).attr("data-userId");
		window.location.href='${path}/user/editorHtml?userId='+ userId;
	});
	$("button[data-type='delect-button']").on("click",function(e){
		var userId = $(this).attr("data-userId");
		$.post("${path}/user/delectUser",{userId:userId},function(data){
			if(data.success){
				location.reload();
			}
		});
	});
	$("#delectUser").on("click",function(){
		var user = "";
		var checkbox=$("input[name='check']");
	    for(i=0;i<checkbox.length;i++){
	        if(checkbox[i].checked){
	        	user = user + checkbox[i].value + ",";
	        }
	    }
	    if(user == ""){
	    	alert("什么都没选中");
	    }else{
	    	$.post("${path}/user/delectUsers",{userIds:user},function(data){
				if(data.success){
					location.reload();
				}
			});
	    }
	})
	$("#testBut").on("click",function(){
		var page = $("#page").val();
		var row = $("#row").val();
		location.href = "${path}/user/list?row="+row+"&page="+page;
	});
	$("#eport").on("click",function(){
		 location.href = "${path}/user/export";
	});
	
	
	var allpro = document.getElementsByName("check");//复选框集合
	var all = document.getElementById("all");//全选按钮
	//全选
	$("input[name='all']").on("click",function(){
		 //全选按钮被选中时，遍历所有按钮
	     if (all.checked) {
	    	 for (var i = 0; i < allpro.length; i++) {
	     		if (allpro[i].type=="checkbox") {
	     			allpro[i].checked=true;
	     		}
	     	 }
	     //全选按钮未被选中时
	     }else{
	     	for (var i = 0; i < allpro.length; i++) {
	     		if (allpro[i].type=="checkbox") {
	     			allpro[i].checked=false;
	     		}
	     	}
	     }
	});
	//点击复选框，检验是否全部选中
	$("input[data-type='click-input']").on("click",function(e){
		var flag = true;
		for (var i = 0; i < allpro.length; i++) {
			if (allpro[i].type=="checkbox" && allpro[i].checked==false) {
     			all.checked = false;
     			flag = false;
     			break;
     		}
			if(flag){
				all.checked = true;
			}
		}
	});
});
</script>
<div>
	<form id="userForm" action="${path}/user/list" method="post">
		<input name="condition">
		<button>查询</button>
	</form>
	<button id="addUser">添加用户</button><button id="delectUser">批量删除</button><button id="eport">批量导出</button><br/><br/>
	<table border="1">
		<tr style="background-color: #C0C0C0;">
			<td>全选<input type="checkbox" name="all" id="all"/></td>
			<td>序号</td>
			<td>账号</td>
			<td>用户名</td>
			<td>性别</td>
			<td>单位</td>
			<td>角色</td>
			<td>加入时间</td>
			<td>状态</td>
			<td>操作</td>
		</tr>
		#foreach ($item in $list)
		<tr>
			<td><input data-type='click-input' type="checkbox" name="check" value="${item.id}" /></td>
			<td>$!{velocityCount}</td>
			<td>${item.realName}</td>
			<td>${item.userName}</td>
			<td>#if($item.sex == 0)<span>男</span>#end #if($item.sex == 1)<span>女</span>#end</td>
			<td>${item.company}</td>
			<td>#if($item.role) ${item.role} #else <span>没有角色</span> #end</td>
			<td>${item.joinTime}</td>
			<td>#if($item.status == 0)<span>启用</span>#end #if($item.status == 1)<span>禁用</span>#end</td>
			<td><button type='button' data-type='editor-button'  data-userId="${item.id}">修改</button>
				<button type='button' data-type='delect-button'  data-userId="${item.id}">删除</button></td>
		</tr>
		#end
	</table><br/>
	输入页数：<input id="page" name="page" />输入条数：<input id="row" name="row" value=""/>
		<button id="testBut">页面跳转</button>
		<br/>
</div>